<?php slot('title',sprintf('Rubicon - Waste & Recycling Management - Invoice #'.$invoice->getInvoiceGroup()))?>
<div class="buttonDiv">
    <form action="" >
      <script type="text/javascript"  language="Javascript">
      function popupPrint(){
        var myWidth = 0;
        var myHeight = 0;
        var popupWidth = 850;
        var popupHeight = 500;
        var screenW = 0;
        var screenH = 0;
        if(document.all){
          screenW = document.body.clientWidth;
          screenH = document.body.clientHeight;
        }else{
          screenW = window.screen.width;
          screenH = window.screen.height;
        }
        if(screenW == 0){
          screenW = popupWidth;
          screenH = popupHeight;
        }

        myWidth = (screenW/2) - ((popupWidth/2) + 10);
        myHeight = (screenH/2) - ((popupHeight/2) + 50);

        // Check for displaying comments
        /*var comments = '&comments=hide';
        if(document.getElementById('showCommentsOnInvoiceChk') && document.getElementById('showCommentsOnInvoiceChk').checked){
          comments = '';
        }*/
        var win2 = window.open("<?php echo url_for('invoice/print?invoice_id='.$invoice->getInvoiceId()) ?>","PrintWindow","status=no,height="+popupHeight+",width="+popupWidth+",resizable=yes,left=" + myWidth + ",top=" + myHeight + ",screenX=" + myWidth + ",screenY=" + myHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
        //win2.focus();
      }
      /*function checkComments(){
        var comments = '&comments=hide';
        if(document.getElementById('showCommentsOnInvoiceChk') && document.getElementById('showCommentsOnInvoiceChk').checked){
          comments = '';
        }
          return comments;
      }*/
    </script>
    <input type="button" value="Download PDF" onclick="document.location='<?php echo url_for('invoice/pdf?invoice_id='.$invoice->getInvoiceId()) ?>'" />
    <input type="button" value="Print" onclick="popupPrint();" />
  </form>
</div>

<table width="800" cellpadding="2" cellspacing="0" border="0" align="center" >
  <tr>
      <td valign="top"><img alt="" src="/images/rubiconlogo.jpg" border="0"></td>
    <td valign="top" align="right">
    <br>
    <table width="300" cellpadding="2" cellspacing="0" style="border: 1px solid #cccccc; ">
      <tr>
        <td bgcolor="#CCCCCC" valign="top">
          <center>
            <font face="arial" size="2"><b>Invoice #<?php echo $invoice->getInvoiceGroup() ?></b></font>
          </center>
        </td>
      </tr>
      <tr>
        <td height="50"  align="left">
          <center>
            <table cellpadding="2" cellspacing="3" border="0">
              <tr>
                <td align="left">
                  <font face="arial" size="2"><b>Date Created:</b></font>
                </td>
                <td align="left">
                  <font face="arial" size="2">
                    <?php echo date("F j, Y", strtotime($invoice->getInvoiceDatestart())) ?>
                  </font>
                </td>
              </tr>
              <?php if($invoice->getInvoiceServicestart() != '0000-00-00' && $invoice->getInvoiceServiceend() != '0000-00-00'): ?>
              <tr>
                <td align="left">
                  <font face="arial" size="2"><b>Service Period:</b> </font>
                </td>
                <td align="left">
                  <font face="arial" size="2">
                    <?php echo date("m/d/Y", strtotime($invoice->getInvoiceServicestart())) ?> - <?php echo date("m/d/Y", strtotime($invoice->getInvoiceServiceend())) ?>
                  </font>
              </tr>
              <?php endif; ?>
              <tr style="color: #dc0000;">
                <td align="left">
                  <font face="arial" size="2" color="#dc0000"><b>Date Due:</b></font>
                </td>
                <td align="left">
                  <font face="arial" size="2" color="#dc0000"><?php echo date("F j, Y", strtotime($invoice->getInvoiceDatestart()) + ($account->getBillingPaymentTerm() * 86400)) ?></font>
                </td>
              </tr>                 
            </table>
          </center>
        </td>
      </tr>
    </table>
    </td>
  </tr>
</table>

<br>

<br>

<table width="800" cellpadding="10" cellspacing="0" border="0" align="center">
  <tr>
    <td align="left" valign="top" width="400">
      <font face="arial" size="2"><b>Customer Information:</b><br>
        <font face="arial" size="4"><b><?php echo strtoupper($account->getAccountName()) ?></b></font>
        <br>
        <font face="arial" size="2">
          <?php echo strtoupper(str_replace("\n", "<br />", $account->getBillingAddress())) ?><br>
          <?php echo strtoupper($account->getBillingCity()) ?>, <?php echo strtoupper($account->getBillingState()) ?> <?php echo strtoupper($account->getBillingZip()) ?><br>
        </font>
      </font>
    </td>
    <td valign="top" align="right" width="400">
      <font face="arial" size="2"><b>Service Address:</b><br>
        <font face="arial" size="2"><?php echo strtoupper($account->getServiceAddress()) ?></font>
        <br>
        <?php echo $account->getServiceCity() ? strtoupper($account->getServiceCity()).',' : '' ?> <?php echo strtoupper($account->getServiceState()) ?> <?php echo strtoupper($account->getServiceZip()) ?>
        <br>
      </font>
    </td>
  </tr>
</table>

<br>

<br>
<?php /*
<center>
  <b><font face="arial" size="4">A Summary of Your Bill For All Accounts Below</font></b>
  <br>
  <br>
</center>

<hr width="800" size="1">
%%%content_totals%%%

<hr width="800" size="1">
%%%content_savings%%%
*/ ?>
<!-- PAGE BREAK -->
<span class="titulo">
  <b><font face="arial" size="4">Your Bill In Full Detail</font></b>

</span>
<br>

                                



<?php
foreach($invoices as $invoice_id):
//echo $services[$invoice_id];
$myRows = $services[$invoice_id]['perminate'];
if(count($myRows) > 0):
  
?>
<table width="800" cellpadding="2" cellspacing="0" style=" " align="center">
  <tr>
    <td align="left" width="700" bgcolor="#DEDEDE" valign="top">
      <font face="arial" size="2"><b>Permanent Service</b>
        <?php
        if($multiInvoices):
          // Display accountname - sericeaddress - servicecity - servicestate - serviceszip
          $aid = $myRows[0]->getAccount();
          //$q = "SELECT * FROM account WHERE account_id='$aid'";
          //$subAccData = $db->query(Database::SELECT, $q)->current();
          $subAccData = Doctrine_Core::getTable('Account')->find($aid);
          echo("&nbsp;&nbsp;&nbsp;&nbsp;");
          echo('<font face="arial" size="1">');
          echo('Acc. #'.$subAccData->getAccountId().' - ');
          ////if(trim($subAccData['store_number']) != ''){
          ////  echo($subAccData['store_number'].' - ');
          ////}
          echo($subAccData->getAccountName().' - '.$subAccData->getServiceAddress().' - '.$subAccData->getServiceCity().' - '.$subAccData->getService_state().' - '.$subAccData->getServiceZip());
          echo('</font>');
        endif;
        ?>
      </font>
    </td>
    <td align="left" width="100" bgcolor="#DEDEDE" valign="top">
      <font face="arial" size="2"><b>Amount</b></font>
    </td>
  </tr>
</table>

<?php
endif;

foreach($myRows as $row):
  //$costs = getServiceCosts($row['serv_group']);
  //$runningBenchmark += $costs['benchmark'];
  //$runningNew += $costs['newprice'];
  $runningBenchmark += $row['row_benchmark'];
  $runningNew += $row['row_newprice'];
  $runningHauler += $row['row_hauler_cost'];
  $dateOrdered = "";
  if($row['row_dateordered'] != "0000-00-00 00:00:00"):
      $dateOrdered = date("m/d/Y", strtotime($row['row_dateordered']));
  endif;
  $haul_cost = $account->getInvoiceFormat() == 'split' ? $row['row_hauler_cost'] : $row['row_newprice'];
  $rubiconFee += $row['row_newprice'] - $row['row_hauler_cost'];
?>
<table width="800" cellpadding="2" cellspacing="1" style=" " align="center">
  <tr>
    <td align="left" width="700" valign="top">
      <font face="arial" size="2"><?php echo $row['row_servicename'] ?></font>
    </td>
    <td align="left" width="100"  valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($haul_cost - $row['row_fuel_fee'] - $row['row_adminfee'] - $row['row_franchise'] - $row['row_latefee'], 2) ?>
      </font>
    </td>
  </tr>
  <?php
  if($account->getInvoiceFormat() == 'split' AND $row['row_newprice'] - $row['row_hauler_cost'] != 0) :
  ?>
  <tr>
    <td align="left"  valign="top">
      <font face="arial" size="2">Rubicon Management Fee</font>
    </td>
    <td align="left"  valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($row['row_newprice'] - $row['row_hauler_cost'], 2) ?>
      </font>
    </td>
  </tr>
  <?php
  endif;

  if($row['row_fuel_fee'] != 0):
  ?>
  <tr>
    <td align="left"  valign="top">
      <font face="arial" size="2">Fuel/Environmental Fee</font>
    </td>
    <td align="left"  valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($row['row_fuel_fee'], 2) ?>
      </font>
    </td>
  </tr>
  <?php
  endif;

  if($row['row_adminfee'] != 0): ?>
  <tr>
    <td align="left"  valign="top">
      <font face="arial" size="2">Admin Fee</font>
    </td>
    <td align="left"  valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($row['row_adminfee'], 2) ?>
      </font>
    </td>
  </tr>
  <?php
  endif;
  if($row['row_franchise'] != 0): ?>
  <tr>
    <td align="left" valign="top">
      <font face="arial" size="2">Franchise Fee</font>
    </td>
    <td align="left" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($row['row_franchise'], 2) ?>
      </font>
    </td>
  </tr>
  <?php
  endif;
  if($row['row_latefee'] != 0): ?>
  <tr>
    <td align="left" valign="top">
      <font face="arial" size="2">Late Fee</font>
    </td>
    <td align="left" valign="top">
        <font face="arial" size="2">
          $<?php echo number_format($row['row_latefee'], 2) ?>
        </font>
    </td>
  </tr>
  <?php 
  endif;
  ?>
</table>

<hr width="800" size="1">
<?php
endforeach;
//if(count($myRows) > 0){
if(false): ?>

<hr width="800" size="1">
<?php endif;



$myRows = $services[$invoice_id]['ondemand'];
$hr = FALSE;

if(count($myRows) > 0):
  $hr = TRUE;
?>
<table width="800" cellpadding="2" cellspacing="0" style=" " align="center">
  <tr>
    <td align="left" width="90" bgcolor="#DEDEDE" valign="top">
      <font face="arial" size="2"><b>Date Ordered</b></font>
    </td>
    <td align="left" width="370" bgcolor="#DEDEDE" valign="top0">
      <font face="arial" size="2"><b>On Call Service</b></font>
    </td>
    <td align="left" width="80" bgcolor="#DEDEDE" valign="top">
      <font face="arial" size="2"><b>Per ton</b></font>
    </td>
    <td align="left" width="80" bgcolor="#DEDEDE" valign="top">
      <font face="arial" size="2"><b>Tonnage</b></font>
    </td>
    <td align="left" width="80" bgcolor="#DEDEDE" valign="top">
        <font face="arial" size="2"><b>Haul</b></font>
    </td>
    <td align="left" width="100" bgcolor="#DEDEDE" valign="top">
      <font face="arial" size="2"><b>Amount</b></font>
    </td>
  </tr>
</table>

<?php
endif;

foreach($myRows as $row):
  $costs = Service::getServiceCosts($row->getGroup(), $account->getRubiconFeePercent());
  //$runningBenchmark	+= $costs['benchmark'];
  //$runningNew += $costs['newprice'];
  $runningBenchmark += $row['row_benchmark'];
  $runningNew += $row['row_newprice'];
  $runningHauler += $row['row_hauler_cost'];
  $dateOrdered = "";

  if($row['row_dateordered'] != "0000-00-00 00:00:00"):
    $dateOrdered = date("m/d/Y", strtotime($row['row_dateordered']));
  endif;

  $name = $row['row_servicename'];
  $perton = floatval($row['row_perton']);
  $tonnage = floatval($row['row_tons']);
  $haul_cost = $account->getInvoiceFormat() == 'split' ? $row['row_hauler_cost'] : $row['row_newprice'];
  $rubiconFee += $row['row_newprice'] - $row['row_hauler_cost'];
?>
<table width="800" cellpadding="2" cellspacing="1" style=" " align="center">
  <tr>
    <td align="left" width="90" valign="top">
      <font face="arial" size="2"><?php echo $dateOrdered ?></font>
    </td>
    <td align="left" width="370" valign="top0">
      <font face="arial" size="2"><?php echo $name ?></font>
    </td>
    <td align="left" width="80" valign="top">
      <font face="arial" size="2">$<?php echo number_format($perton, 2) ?></font>
    </td>
    <td align="left" width="80" valign="top">
      <font face="arial" size="2"><?php echo number_format($tonnage, 2) ?></font>
    </td>
    <td align="left" width="80"  valign="top">
      <font face="arial" size="2">$<?php echo number_format($row['row_haul_cost'], 2) ?></font>
    </td>
    <td align="left" width="100" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($haul_cost - $row['row_fuel_fee'] - $row['row_adminfee'] - $row['row_franchise'] - $row['row_latefee'], 2) ?>
      </font>
    </td>
  </tr>
  <?php
  if($account->getInvoiceFormat() == 'split' AND $row['row_newprice'] - $row['row_hauler_cost'] != 0):
  ?>
  <tr>
    <td align="left" valign="top">
      <font face="arial" size="2"><?php echo $dateOrdered ?></font>
    </td>
    <td align="left"valign="top">
      <font face="arial" size="2">Rubicon Management Fee</font>
    </td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($row['row_newprice'] - $row['row_hauler_cost'], 2) ?>
      </font>
    </td>
  </tr>
  <?php
  endif;

  if($row['row_fuel_fee'] != 0):
  ?>
  <tr>
    <td align="left" valign="top">
      <font face="arial" size="2"><?php echo $dateOrdered ?></font>
    </td>
    <td align="left" valign="top">
      <font face="arial" size="2">Fuel/Environmental Fee</font>
    </td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($row['row_fuel_fee'], 2) ?>
      </font>
    </td>
  </tr>
  <?php
  endif;

  if($row['row_adminfee'] != 0):
  ?>
  <tr>
    <td align="left" valign="top">
      <font face="arial" size="2"><?php echo $dateOrdered ?></font>
    </td>
    <td align="left" valign="top">
      <font face="arial" size="2">Admin Fee</font>
    </td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($row['row_adminfee'], 2) ?>
      </font>
    </td>
  </tr>
  <?php endif;
  if($row['row_franchise'] != 0): ?>
  <tr>
    <td align="left" valign="top">
      <font face="arial" size="2"><?php echo $dateOrdered ?></font>
    </td>
    <td align="left" valign="top">
      <font face="arial" size="2">Franchise Fee</font>
    </td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top"></td>
    <td align="left" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($row['row_franchise'], 2) ?></font>
    </td>
  </tr>
  <?php endif;
  if($row['row_latefee'] != 0): ?>
 <tr>
   <td align="left" valign="top">
     <font face="arial" size="2"><?php echo $dateOrdered ?></font>
   </td>
   <td align="left" valign="top">
     <font face="arial" size="2">Late Fee</font>
   </td>
   <td align="left" valign="top"></td>
   <td align="left" valign="top"></td>
   <td align="left" valign="top"></td>
   <td align="left" valign="top">
     <font face="arial" size="2">
       $<?php echo number_format($row['row_latefee'], 2) ?>
     </font>
   </td>
 </tr>
 <?php endif; ?>
</table>
<?php  endforeach; 

$myRows = $services[$invoice_id]['item'];
if(count($myRows) > 0):
$hr = TRUE;
?>
<table width="800" cellpadding="2" cellspacing="0" style=" " align="center">
  <tr>
    <td align="left" width="110" bgcolor="#DEDEDE" valign="top">
      <font face="arial" size="2"><b>Date</b></font>
    </td>
    <td align="left" width="390" bgcolor="#DEDEDE" valign="top">
      <font face="arial" size="2"><b>Service</b></font>
    </td>
    <td align="left" width="100" bgcolor="#DEDEDE" valign="top">
      <font face="arial" size="2"><b>Unit Price</b></font>
    </td>
    <td align="left" width="100" bgcolor="#DEDEDE" valign="top">
      <font face="arial" size="2"><b>Quantity</b></font>
    </td>
    <td align="left" width="100" bgcolor="#DEDEDE" valign="top">
      <font face="arial" size="2"><b>Total</b></font>
    </td>
  </tr>
</table>

<table width="800" cellpadding="2" cellspacing="1" style=" " align="center">
<?php
foreach($myRows as $row):
  $date = '<em>None</em>';

  if($row['row_dateordered'] != '0000-00-00 00:00:00'):
    $date = date("m/d/Y", strtotime($row['row_dateordered']));
  endif;

  $runningBenchmark += $row['row_item_price'] * $row['row_item_qty'];
  $runningNew += $row['row_item_price'] * $row['row_item_qty'];
  $runningHauler += $row['row_item_price'] * $row['row_item_qty'];
?>
  <tr>
    <td align="left" width="110" valign="top">
      <font face="arial" size="2"><?php echo $date ?></font>
    </td>
    <td align="left" width="390" valign="top">
      <font face="arial" size="2"><?php echo $row['row_servicename'] ?></font>
    </td>
    <td align="left" width="100" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($row['row_item_price'], 2) ?>
      </font>
    </td>
    <td align="left" width="100" valign="top">
      <font face="arial" size="2">
        <?php echo number_format($row['row_item_qty'], 0) ?> <?php echo $row['row_item_unit'] ?>
      </font>
    </td>
    <td align="left" width="100" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($row['row_item_price'] * $row['row_item_qty'], 2) ?>
      </font>
    </td>
  </tr>
<?php
  endforeach;
?>
</table>
<?php
endif; // End itemized loop

$res = Doctrine_Core::getTable('Credit')->findByInvoiceId($invoice_id);
/*$q = "SELECT * FROM credit WHERE invoice_id=$invoice_id";// AND account_id=$account_id"; This messed up creation of master invoices
                                    $res = $db->query(Database::SELECT, $q);*/
foreach($res as $row):
 $displayDate = date("m/d/Y", strtotime($row['credit_date']));
 $name = $row['credit_desc'];
 $neg = '';
 if($row['credit_type'] == 'credit'):
   $neg = '-';
   $name = "Credit: $name";
   $totalCreditAmount -= $row['credit_amount'];
 elseif($row['credit_type'] == 'fee'):
   $totalCreditAmount += $row['credit_amount'];
 elseif($row['credit_type'] == 'rubiconfee'):
   //$totalCreditAmount += $row['credit_amount'];
   $runningNew += $row['credit_amount'];
   $rubiconFee += $row['credit_amount'];
 else:
   $name = "Debit: $name";
   $totalCreditAmount += $row['credit_amount'];
 endif;

 $amount = $neg.'$'.number_format($row['credit_amount'], 2);
?>
<table width="800" cellpadding="2" cellspacing="1" style=" " align="center">
  <tr>
    <td align="left" width="90" valign="top">
      <font face="arial" size="2"><?php echo $displayDate ?></font>
    </td>
    <td align="left" width="370" valign="top">
      <font face="arial" size="2"><?php echo $name ?></font>
    </td>
    <td align="left" width="80" valign="top"></td>
    <td align="left" width="80" valign="top"></td>
    <td align="left" width="80" valign="top"></td>
    <td align="left" width="100" valign="top">
      <font face="arial" size="2"><?php echo $amount ?></font>
    </td>
  </tr>
</table>
<?php
endforeach;

if($hr):
?>
<hr width="800" size="1">
<?php
endif;
endforeach; // End multi invoice loop

$hauler_pricing = $account->getInvoiceFormat() == 'split' ? $runningNew - $rubiconFee : $runningNew;

//ob_start();
?>

<table width="800" cellpadding="2" cellspacing="1" style=" " align="center">
  <tr>
    <td width="100" valign="top">&nbsp;</td>
    <td width="400" valign="top0">&nbsp;</td>
    <td align="left" width="200" valign="top">
      <font face="arial" size="2"><b>Your Price Would Have Been</b></font>
    </td>
    <td align="left" width="100" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($runningBenchmark, 2) ?>
      </font>
    </td>
  </tr>
</table>
<table width="800" cellpadding="2" cellspacing="1" style=" " align="center">
  <tr>
    <td width="100" valign="top">&nbsp;</td>
    <td width="400" valign="top0">&nbsp;</td>
    <td align="left" width="200" valign="top">
      <font face="arial" size="2"><b>Rubicon Hauler Pricing</b></font>
    </td>
    <td align="left" width="100" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($hauler_pricing, 2) ?>
      </font>
    </td>
  </tr>
</table>
<table width="800" cellpadding="2" cellspacing="1" style=" " align="center">
  <tr>
    <td width="100" valign="top">&nbsp;</td>
    <td width="400" valign="top0">&nbsp;</td>
    <td align="left" width="200" valign="top">
      <font face="arial" size="2"><b>Total Hauler Savings</b></font>
    </td>
    <td align="left" width="100" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($runningBenchmark - $hauler_pricing, 2) ?>
      </font>
    </td>
  </tr>
</table>
<?php if($rubiconFee != 0 AND $account->getInvoiceFormat() == 'split'): ?>
<table width="800" cellpadding="2" cellspacing="1" style=" " align="center">
  <tr>
    <td width="100" valign="top">&nbsp;</td>
    <td width="400" valign="top0">&nbsp;</td>
    <td align="left" width="200" valign="top">
      <font face="arial" size="2"><b>Rubicon Management Fee</b></font>
    </td>
    <td align="left" width="100" valign="top">
      <font face="arial" size="2">
        $<?php echo number_format($rubiconFee, 2) ?>
      </font>
    </td>
  </tr>
</table>
<?php endif; ?>

<table width="800" cellpadding="2" cellspacing="1" style=" " align="center">
  <tr>
    <td width="100" valign="top">&nbsp;</td>
    <td width="400" valign="top">&nbsp;</td>
    <td align="left" width="200" valign="top">
      <font face="arial" size="4"><b>Pay this amount</b></font>
    </td>
    <td align="left" width="100" valign="top">
      <font face="arial" size="4">
        <b>$<?php echo number_format($runningNew + $totalCreditAmount, 2) ?></b>
      </font>
    </td>
  </tr>
</table>

<hr width="800" size="1">

<?php
/*$content_totals = ob_get_contents();
ob_end_clean();
echo($content_totals);*/

//ob_start();
?>
<center>
  <b><font face="arial" size="4">Rubicon Savings Summary Below</font></b>
  <br>
  <br>
  <table width="800" cellpadding="2" cellspacing="1" style=" ">
    <tr>
      <td width="266" bgcolor="#CCCCCC" valign="top">
        <center>
          <font face="arial" size="2"><b>This Month's Hauler Savings</b></font>
        </center>
      </td>
      <td width="266" bgcolor="#CCCCCC" valign="top">
        <center>
          <font face="arial" size="2"><b>Year To Date Hauler Saving</b></font>
        </center>
      </td>
      <td width="266" bgcolor="#CCCCCC" valign="top">
        <center>
          <font face="arial" size="2"><b>Rubicon Total Hauler Savings</b></font>
        </center>
      </td>
    </tr>
  </table>
  <table width="800" cellpadding="2" cellspacing="1" style=" ">
    <tr>
      <td width="266" valign="top">
        <center>
          <font face="arial" size="2"><b>$<?php echo number_format($runningBenchmark - $hauler_pricing, 2) ?></b></font>
        </center>
      </td>
      <?php
      // List of all accounts to check for savings stats
      $subAccounts[] = $account->getAccountId(); // Add current account id
      $accStr = implode(',', $subAccounts);

      // Lookup ytd savings and all time savings
      $allTime = Doctrine_Core::getTable('Invoice')->getSavingsTotal($accStr);

      $myinvoicedate = $invoice->getInvoiceDateend();
      $yearstart = date("Y", strtotime($myinvoicedate));

      $ytd = Doctrine_Core::getTable('Invoice')->getSavingsYear($accStr,$myinvoicedate,$yearstart);
      ?>
      <td width="266" valign="top">
        <center>
          <font face="arial" size="2">
            <b>$<?php echo number_format($ytd['total_benchmark'] - ($ytd['total_newprice'] - ($ytd['total_benchmark'] - $ytd['total_newprice'])), 2) ?></b>
          </font>
        </center>
      </td>
      <td width="266" valign="top">
        <center>
          <font face="arial" size="2">
            <b>$<?php echo number_format($allTime['total_benchmark'] - ($allTime['total_newprice'] - ($allTime['total_benchmark'] - $allTime['total_newprice'])), 2) ?></b>
          </font>
        </center>
      </td>
    </tr>
  </table>
  <br>
  <br>
  <?php
  /*$content_savings = ob_get_contents();
  ob_end_clean();
  echo($content_savings);*/
/*
  if(trim($invoice->getInvoiceComments()) != "" && $showcomments) :
  ?>
  <b><font face="arial" size="2">Comments</font></b>
  <table cellpadding="0" cellspacing="0" border="1" style="border: 1px solid #CCCCCC;" width="800">
    <tr>
      <td align="left">
        <div style="padding: 5px;">
          <?php echo $invoice->getInvoiceComments() ?>
        </div>
      </td>
    </tr>
  </table>
  <?php
  endif;*/
  ?>

  <center>
    <b><font face="arial" size="4">Thank You for Your Business!</font></b><br>
    <br>
    <hr width="800" size="1">
    <center>
    <br>
      <center>
        <font face="arial" size="2"></font>
      </center>
    </center>
  </center>
</center>
<?php
/*$content_entire = ob_get_contents();
ob_end_clean();
// Input content_totals, content_savings
$content_entire = str_replace('%%%content_totals%%%', $content_totals, $content_entire);
$content_entire = str_replace('%%%content_savings%%%', $content_savings, $content_entire);*/
//echo($content_entire);
/*?>

<table align="center">
  <tbody>
    <tr>
      <th>Invoice:</th>
      <td><?php echo $invoice->getInvoiceId() ?></td>
    </tr>
    <tr>
      <th>Invoice group:</th>
      <td><?php echo $invoice->getInvoiceGroup() ?></td>
    </tr>
    <tr>
      <th>Invoice groupdate:</th>
      <td><?php echo $invoice->getInvoiceGroupdate() ?></td>
    </tr>
    <tr>
      <th>Invoice datestart:</th>
      <td><?php echo $invoice->getInvoiceDatestart() ?></td>
    </tr>
    <tr>
      <th>Invoice dateend:</th>
      <td><?php echo $invoice->getInvoiceDateend() ?></td>
    </tr>
    <tr>
      <th>Invoice servicestart:</th>
      <td><?php echo $invoice->getInvoiceServicestart() ?></td>
    </tr>
    <tr>
      <th>Invoice serviceend:</th>
      <td><?php echo $invoice->getInvoiceServiceend() ?></td>
    </tr>
    <tr>
      <th>Invoice benchmark:</th>
      <td><?php echo $invoice->getInvoiceBenchmark() ?></td>
    </tr>
    <tr>
      <th>Invoice newprice:</th>
      <td><?php echo $invoice->getInvoiceNewprice() ?></td>
    </tr>
    <tr>
      <th>Invoice hauler cost:</th>
      <td><?php echo $invoice->getInvoiceHaulerCost() ?></td>
    </tr>
    <tr>
      <th>Invoice comments:</th>
      <td><?php echo $invoice->getInvoiceComments() ?></td>
    </tr>
    <tr>
      <th>Invoice deleted:</th>
      <td><?php echo $invoice->getInvoiceDeleted() ?></td>
    </tr>
    <tr>
      <th>Invoice paid:</th>
      <td><?php echo $invoice->getInvoicePaid() ?></td>
    </tr>
    <tr>
      <th>Invoice hauler paid:</th>
      <td><?php echo $invoice->getInvoiceHaulerPaid() ?></td>
    </tr>
    <tr>
      <th>Invoice sent:</th>
      <td><?php echo $invoice->getInvoiceSent() ?></td>
    </tr>
    <tr>
      <th>Invoice send date:</th>
      <td><?php echo $invoice->getInvoiceSendDate() ?></td>
    </tr>
    <tr>
      <th>Invoice last send:</th>
      <td><?php echo $invoice->getInvoiceLastSend() ?></td>
    </tr>
    <tr>
      <th>Invoice paid date:</th>
      <td><?php echo $invoice->getInvoicePaidDate() ?></td>
    </tr>
    <tr>
      <th>Account:</th>
      <td><?php echo $invoice->getAccountId() ?></td>
    </tr>
  </tbody>
</table>

<hr />

<a href="<?php echo url_for('invoice/edit?invoice_id='.$invoice->getInvoiceId()) ?>">Edit</a>
&nbsp;
 <a href="<?php echo url_for('invoice/index') ?>">List</a>*/
